@page "/docio/word-to-wordml"
@inject Microsoft.JSInterop.IJSRuntime JS
@using System.IO
@using Syncfusion.Blazor.Buttons
@using BlazorDemos.Data.FileFormats.DocIO
@using Microsoft.AspNetCore.Http;
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment
@inherits SampleBaseComponent;

<SampleDescription>
    <p style="font-size:16px">This sample demonstrates how to convert the Word document to Word processing XML using Essential DocIO.</p>
</SampleDescription>
<ActionDescription>
 <p style="font-size:16px">DocIO provides support to convert the Word document to Word processing XML document and vice versa.</p>
 <p style="font-size:16px">More information about WordML conversion can be found on this  <a href="https://help.syncfusion.com/file-formats/docio/word-file-formats#word-processing-xml-xml">documentation</a> section.</p>
</ActionDescription>

<div class="control-section">
    <p style="font-size:16px">Click the button to view the resultant WordML document generated by Essential DocIO.</p>
    <div class="button-section">
        <div id="button-control">
            <div class="row">
                <div>
                    <SfButton @onclick="ViewTemplate">View Template</SfButton>&nbsp;
                    <SfButton @onclick="ConvertToWordML">Convert to WordML</SfButton>
                </div>
            </div>
        </div>
    </div>
</div>


<style>
    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream documentStream;

    /// <summary>
    /// Convert the Word document to Word processing XML
    /// </summary>
    public async Task ConvertToWordML(MouseEventArgs args)
    {
        WordToWordMLService service = new WordToWordMLService(hostingEnvironment);
        documentStream = service.WordToWordML("ConvertToWordML");
        await JS.SaveAs("WordToWordML.xml", documentStream.ToArray());
    }
    /// <summary>
    /// Download the template Word document
    /// </summary>
    public async Task ViewTemplate(MouseEventArgs args)
    {
        WordToWordMLService service = new WordToWordMLService(hostingEnvironment);
        documentStream = service.WordToWordML("View Template");
        await JS.SaveAs("DocToWordML.doc", documentStream.ToArray());        
    }
}